import Vue from 'vue'
// import Vue from 'vue/dist/vue.js'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './api/mock'
import Cookie from 'js-cookie'
import BaiduMap from 'vue-baidu-map'

// 分页组件
import Pagination from '@/Components/Pagination'
// 视频播放器插件
import VueCoreVideoPlayer from 'vue-core-video-player'

// 引入easyUI
import 'vx-easyui/dist/themes/default/easyui.css'
import 'vx-easyui/dist/themes/icon.css'
import 'vx-easyui/dist/themes/vue.css'
import EasyUI from 'vx-easyui'

// 导入ng-form组件库
//  https://gitee.com/jjxliu306/ng-form-element#%E5%AE%89%E8%A3%85
import NgFormElement from 'ng-form-element'
import 'ng-form-element/lib/ng-form-element.css'

// 引入大屏边框组件dataV
import dataV from '@jiaminghi/data-view'

// 引入和风天气图标
import 'qweather-icons/font/qweather-icons.css'

// 设备选择组件
import ElInputDevSelect from '@/Components/ElInputDevSelect'

// 右键点击事件（右键生成菜单）
import VueContextMenu from 'vue-contextmenu'
// vue-json-viewer https://www.npmjs.com/package/vue-json-viewer?activeTab=readme
import JsonViewer from 'vue-json-viewer'
Vue.use(VueContextMenu)
Vue.use(EasyUI)

Vue.use(ElementUI)
Vue.use(VueCoreVideoPlayer)

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'PlhFWpA02aoURjAOpnWcRGqw7AI8EEyO'
})

Vue.use(dataV)
Vue.use(NgFormElement)
Vue.use(JsonViewer)

Vue.component('ElInputDevSelect', ElInputDevSelect)// 挂载全局组件

Vue.component('Pagination', Pagination)

Vue.config.productionTip = false

// 添加全局前置导航守卫
router.beforeEach((to, from, next) => {
  // 每次在路由跳转的时候设置浏览器的缩放
  document.body.style.zoom = '100%'

  const token = Cookie.get('token')
  // 判断当token不存在且要跳转的页面不是login页面时，跳转到login页面
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else if (token && to.name === 'login') {
    // 如果token存在，且当前页面要跳转到login页面，就跳转到首页
    next({ name: 'home' })
  } else {
    next()
  }
})

// 控制浏览器的缩放
window.onload = function () {
  document.body.style.zoom = '100%'
}

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
